package com.mooc.dto;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Result implements Serializable {

    private int code; // 编码：1成功，0和其它数字为失败
    private String msg; // 错误信息
    private Map<String, Object> data = new HashMap<>(); // 数据

    // 成功且无数据
    public static Result success() {
        Result result = new Result();
        result.setCode(1);
        return result;
    }

    // 成功且有数据
    public static Result success(String key, Object value) {
        Result result = new Result();
        result.setCode(1);
        result.data.put(key, value);
        return result;
    }

    // 失败
    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

}
